package subscriberPanels;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;

import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import clientGUI.ConnectionGUI;
import clientGUI.MainGUI;
import clientGUI.PanelDesign;

public class ViewMyReaderCardPanel extends PanelDesign { 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static JTextField textFieldID;
	private static JTextField textFieldFirstN;
	private static JTextField textFieldLastN;
	private static JTextField textFieldCardStatus;
	private static JTextField textFieldPhone;
	private static JTextField textFieldEMail;
	private static JTable borrowedTable;
	private static JTable historyTable;
	private static JTable actionsTable;


	  /**
	 * Create the panel.
	 */
	public ViewMyReaderCardPanel() {
		setLayout(null);
		setPreferredSize(new Dimension(644, 462));

		
		JPanel history=new JPanel();
		JPanel details=new JPanel();

		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(3, 3, 638, 456);
		tabbedPane.addTab("My Details", details);
		details.setLayout(null);
		JLabel lbtitle = new JLabel("My Reader Card:");
		lbtitle.setBounds(248, 11, 136, 20);
		details.add(lbtitle);
		lbtitle.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		JLabel lblMyBooks = new JLabel("My books:");
		lblMyBooks.setBounds(273, 159, 86, 14);
		details.add(lblMyBooks);
		lblMyBooks.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		JLabel lblPhoneNumber = new JLabel("Phone Number:");
		lblPhoneNumber.setBounds(86, 112, 86, 20);
		details.add(lblPhoneNumber);
		lblPhoneNumber.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		textFieldPhone = new JTextField();
		textFieldPhone.setBounds(182, 113, 117, 20);
		details.add(textFieldPhone);
		textFieldPhone.setEditable(false);
		textFieldPhone.setColumns(10);
		
		textFieldCardStatus = new JTextField();
		textFieldCardStatus.setBounds(182, 85, 117, 20);
		details.add(textFieldCardStatus);
		textFieldCardStatus.setEditable(false);
		textFieldCardStatus.setColumns(10);
		
		JLabel lblCardStatus = new JLabel("Card Status:");
		lblCardStatus.setBounds(86, 85, 71, 20);
		details.add(lblCardStatus);
		lblCardStatus.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblId = new JLabel("ID:");
		lblId.setBounds(86, 60, 46, 14);
		details.add(lblId);
		lblId.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		textFieldID = new JTextField();
		textFieldID.setBounds(182, 54, 117, 20);
		details.add(textFieldID);
		textFieldID.setEditable(false);
		textFieldID.setColumns(10);
		
		JLabel lblEmail = new JLabel("E-Mail:");
		lblEmail.setBounds(338, 111, 61, 20);
		details.add(lblEmail);
		lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		textFieldEMail = new JTextField();
		textFieldEMail.setBounds(413, 112, 117, 20);
		details.add(textFieldEMail);
		textFieldEMail.setEditable(false);
		textFieldEMail.setColumns(10);
		
		textFieldLastN = new JTextField();
		textFieldLastN.setBounds(413, 84, 117, 20);
		details.add(textFieldLastN);
		textFieldLastN.setEditable(false);
		textFieldLastN.setColumns(10);
		
		JLabel lblLastName = new JLabel("Last Name:");
		lblLastName.setBounds(338, 83, 71, 20);
		details.add(lblLastName);
		lblLastName.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblFirstName = new JLabel("First Name:");
		lblFirstName.setBounds(338, 55, 71, 23);
		details.add(lblFirstName);
		lblFirstName.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		textFieldFirstN = new JTextField();
		textFieldFirstN.setBounds(413, 53, 117, 20);
		details.add(textFieldFirstN);
		textFieldFirstN.setEditable(false);
		textFieldFirstN.setColumns(10);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(86, 186, 444, 116);
		details.add(scrollPane_1);
		
		borrowedTable = new JTable();
		scrollPane_1.setViewportView(borrowedTable);
		
		
		borrowedTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Book Name", "Borrow Date", "Expected Return Date"
			}
		));
		
		
		tabbedPane.addTab("My History", history);
		history.setLayout(null);
		
		JLabel lblMyBorrowedBook = new JLabel("My Borrowed Book History:");
		lblMyBorrowedBook.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblMyBorrowedBook.setBounds(186, 42, 247, 35);
		history.add(lblMyBorrowedBook);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(43, 90, 549, 211);
		history.add(scrollPane);
		
		historyTable = new JTable();
		scrollPane.setViewportView(historyTable);
		

		history.setLayout(null);
		
		historyTable.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null, null, null}, {null, null, null, null, null},
					{null, null, null, null, null}, {null, null, null, null, null},
					{null, null, null, null, null}, {null, null, null, null, null},
					{null, null, null, null, null}, {null, null, null, null, null},
					{null, null, null, null, null}, {null, null, null, null, null},
					{null, null, null, null, null}, {null, null, null, null, null},
			
				},
				new String[] {
					"Book Name", "Borrow Date" ,"Expected Return Date", "Return Date" , "Incident"
				}));
			

		
		JPanel actions=new JPanel();
		tabbedPane.addTab("My Actions", actions);
		actions.setLayout(null);
		
		JLabel lblMyActions = new JLabel("My Actions:");
		lblMyActions.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblMyActions.setBounds(259, 30, 119, 28);
		actions.add(lblMyActions);
		
		JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(96, 68, 435, 223);
		actions.add(scrollPane_2);
		
		actionsTable = new JTable();
		scrollPane_2.setViewportView(actionsTable);
		
		
		actionsTable.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
					{null, null}, {null, null},
			
				},
				new String[] {
					"Date", "Description"
				}));

		
		add(tabbedPane);

	
		String s1[]=new String[2];
		s1[0]="ViewMyReaderCard";
		//s1[1]="1111";   
		s1[1]= ConnectionGUI.user.id;
		MainGUI.OBLClient.handleMessageFromClient(s1);
	
		
		remove(background);
		add(background);		
		JLabel x=new JLabel();
		x.setIcon(background.getIcon());
		x.setBounds(new Rectangle(0, 0, 638, 456));
		JLabel y=new JLabel();
		y.setIcon(background.getIcon());
		y.setBounds(new Rectangle(0, 0, 638, 456));
		JLabel z=new JLabel();
		z.setIcon(background.getIcon());
		z.setBounds(new Rectangle(0, 0, 638, 456));
		actions.add(z);
		history.add(x);
		details.add(y);
	}
	
	/**
	 * Initialize the data of the fields in the first tab in this panel from the given Matrix.
	 * @param infoSubscriber
	 */
	public static void changeDetailsContent(String[][] infoSubscriber)
	{
		
		textFieldID.setText(infoSubscriber[0][0]);
		textFieldFirstN.setText(infoSubscriber[0][1]);
		textFieldLastN.setText(infoSubscriber[0][2]);
		textFieldPhone.setText(infoSubscriber[0][3]);
		textFieldEMail.setText(infoSubscriber[0][4]);
		if(infoSubscriber[0][5].compareTo("1")==0)
		{
			textFieldCardStatus.setText("Active");
		}
		else if(infoSubscriber[0][5].compareTo("0")==0)
		{
			textFieldCardStatus.setText("Locked");
		}
		else
			textFieldCardStatus.setText("Frozen");
		
		
	}
	
	
	/**
	 * Initialize the data of the table in the first tab this panel with the given Matrix.
	 * @param infoTable
	 */
	public static void changeTableContentMyBook(String[][] infoTable){
		borrowedTable.setModel(new DefaultTableModel(infoTable,	new String[] {
				"Book Name", "Borrow Date" ,"Expected Return Date" 
			}){
				private static final long serialVersionUID = 1L;
				public boolean isCellEditable(int row, int column) {
				return false;
			}
			 });
		borrowedTable.getTableHeader().setReorderingAllowed(false); 
		borrowedTable.getColumnModel().getColumn(0).setResizable(false);
		borrowedTable.getColumnModel().getColumn(1).setResizable(false);
		borrowedTable.getColumnModel().getColumn(2).setResizable(false);
		borrowedTable.getColumnModel().getColumn(0).setPreferredWidth(70);
		borrowedTable.getColumnModel().getColumn(1).setPreferredWidth(70);
		borrowedTable.getColumnModel().getColumn(2).setPreferredWidth(120);
		
		}
	
	/**
	 * Initialize the data of the table in the second tab in this panel with the given Matrix.
	 * @param infoTable
	 */
	public static void changeTableContentMyHistory(String[][] infoTable){
		historyTable.setModel(new DefaultTableModel(infoTable, new String[] {
				"Book Name", "Borrow Date", "Expected Return Date"  ,"Return Date" , "Incedent"
			}){
				private static final long serialVersionUID = 1L;
				public boolean isCellEditable(int row, int column) {
					return false;
				}
			  });
		historyTable.getTableHeader().setReorderingAllowed(false); 
		historyTable.getColumnModel().getColumn(0).setResizable(false);
		historyTable.getColumnModel().getColumn(1).setResizable(false);
		historyTable.getColumnModel().getColumn(2).setResizable(false);
		historyTable.getColumnModel().getColumn(3).setResizable(false);
		historyTable.getColumnModel().getColumn(4).setResizable(false);
		historyTable.getColumnModel().getColumn(0).setPreferredWidth(85);
		historyTable.getColumnModel().getColumn(1).setPreferredWidth(70);
		historyTable.getColumnModel().getColumn(2).setPreferredWidth(130);
		historyTable.getColumnModel().getColumn(3).setPreferredWidth(70);
		historyTable.getColumnModel().getColumn(4).setPreferredWidth(40);
			}
	
	/**
	 * Initialize the data of the table in the third tab in this panel with the given Matrix.
	 * @param infoTable
	 */
	public static void changeTableContentMyActions(String[][] infoTable){
		actionsTable.setModel(new DefaultTableModel(infoTable, new String[] {
				"Date" , "Description"
			}){
				private static final long serialVersionUID = 1L;
				public boolean isCellEditable(int row, int column) {
					return false;
				}
			  });
		actionsTable.getTableHeader().setReorderingAllowed(false); 
		actionsTable.getColumnModel().getColumn(0).setResizable(false);
		actionsTable.getColumnModel().getColumn(1).setResizable(false);
		actionsTable.getColumnModel().getColumn(0).setPreferredWidth(50);
		actionsTable.getColumnModel().getColumn(1).setPreferredWidth(250);
			}
	
	
	
}
